import React from 'react';
import { getClientRender, ApplyPluginsType, dynamic, getDynamicModule, utils } from '@sui/sui';
import plugin from '@@/core/plugin';
import models, { dispatcher } from './model';
import * as Plugin_model from './plugin-model';
import * as Plugin_access from './plugin-access';

import { fallback } from '@@/core/runtime';
const { pick, uuid } = utils;

// 注册插件

plugin.register({
  apply: Plugin_access,
  path: './.sui/plugin-access'
})

plugin.register({
  apply: Plugin_model,
  path: './.sui/plugin-model'
})

// 导入并注册remote应用
const remotes = {

}

//创建路由
const routes = [
	{
		"path": "/",
		"component": require('@/pages/index.tsx').default
	}
] || [];

// on start
plugin.applyPlugins({
  key:"onStart",
  type: ApplyPluginsType.action,
  args: {
    plugin
  }
})

// routes filter
plugin.applyPlugins({
    key: "modifyRoutes",
    type: ApplyPluginsType.action,
    args: {
        routes
    }
})

routes.push(...[{
            "path": "/~sui",
            "component": require('@@/Sui').default
        }])


const suiOpts = {
      version: "3.0.3",
      routes,
      plugin,
      models,
      remotes,
      dispatcher,
      __client_render_id__: uuid()
}

// 运行时渲染配置项，可级调用覆盖
const renderOpts = {
      mountContainer: "root",
      history: {"type":"hash","basename":"/"},
}

export default function render(opts){
    const options = Object.assign({}, renderOpts, opts || {}, suiOpts)
    const clientRender = getClientRender(options)
    return clientRender()
}

